//
//  AddFaceViewController.m
//  NewPro
//
//  Created by RYX on 2018/10/25.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "AddFaceViewController.h"
#import "ScanBCViewController.h"
#import "ScanIdList.h"
#import "ScanIdModel.h"
#import "RealNameParametersModel.h"
@interface AddFaceViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
    
    __weak IBOutlet UIImageView *headerIm;
    __weak IBOutlet UIButton *takePhotoBtn;
}
@end

@implementation AddFaceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNavBarWithTitle:@"实名认证"];

    headerIm.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(takePhoto)];
    [headerIm addGestureRecognizer:tap];
}
- (IBAction)onTakePhotoBtn:(UIButton *)sender {
    
    if ([sender.currentTitle isEqualToString:@"拍照"]) {
        
        if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            
            return [self showMBPError:@"未发现摄像头"];
            
        }
        
        [self takePhoto];
        
        
    }else{
        
        ScanBCViewController *VC = [[ScanBCViewController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    }
    

}

- (void)takePhoto{
    
    UIImagePickerController * picker = [[UIImagePickerController alloc]init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    [self presentViewController:picker animated:YES completion:nil];
    
}
#pragma mark - 相册选择完成
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    
    [picker dismissViewControllerAnimated:YES completion:^{
        
        UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
        
        self->headerIm.image = image;
        
        [ScanIdList sharedInstance].scanModel.photoImgage = image;
        
        [ScanIdList sharedInstance].realNameModel.bankBackImgData = [ImgManager imageToString:image];
        
        [self->takePhotoBtn setTitle:@"下一步" forState:UIControlStateNormal];
        
    }];
}


@end
